﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="juhiluba", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Juhiluba))]
    public class JuhilubaSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IJuhiluba clazz;
        
        public JuhilubaSerializer(IJuhiluba clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("loa_nr");
            if (clazz.LoaNr!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LoaNr))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : LoaNr");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("loa_tyyp");
            if (clazz.LoaTyyp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LoaTyyp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : LoaTyyp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("loa_staatus");
            if (clazz.LoaStaatus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LoaStaatus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : LoaStaatus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("loa_staatuse_kp");
            if (clazz.LoaStaatuseKp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LoaStaatuseKp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : LoaStaatuseKp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kategooriad");
            if (clazz.Kategooriad!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kategooriad))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Kategooriad");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("valja_kp");
            if (clazz.ValjaKp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ValjaKp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ValjaKp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("katte_kp");
            if (clazz.KatteKp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KatteKp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KatteKp");
            }
            Writer.WriteEndElement();
            if (clazz.KehtivKp!=null) {
                Writer.WriteStartElement("kehtiv_kp");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KehtivKp))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("lisaandmed");
            if (clazz.Lisaandmed!=null) {
                global::Xtee.Core.SerializationMetadata metaLisaandmed = this.GetMetaData(clazz.Lisaandmed);
                Writer.WriteTypeAttribute(metaLisaandmed.TypeQualifiedName.Namespace, metaLisaandmed.TypeQualifiedName.Name);
                metaLisaandmed.NewSerializer(clazz.Lisaandmed).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Lisaandmed");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("juhiluba_kehtib");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.JuhilubaKehtib))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "loa_nr")) {
                goto loa_nr;
            }
            else {
                if ((Reader.LocalName == "loa_tyyp")) {
                    goto loa_tyyp;
                }
                else {
                    if ((Reader.LocalName == "loa_staatus")) {
                        goto loa_staatus;
                    }
                    else {
                        if ((Reader.LocalName == "loa_staatuse_kp")) {
                            goto loa_staatuse_kp;
                        }
                        else {
                            if ((Reader.LocalName == "kategooriad")) {
                                goto kategooriad;
                            }
                            else {
                                if ((Reader.LocalName == "valja_kp")) {
                                    goto valja_kp;
                                }
                                else {
                                    if ((Reader.LocalName == "katte_kp")) {
                                        goto katte_kp;
                                    }
                                    else {
                                        if ((Reader.LocalName == "kehtiv_kp")) {
                                            goto kehtiv_kp;
                                        }
                                        else {
                                            if ((Reader.LocalName == "lisaandmed")) {
                                                goto lisaandmed;
                                            }
                                            else {
                                                if ((Reader.LocalName == "juhiluba_kehtib")) {
                                                    goto juhiluba_kehtib;
                                                }
                                                else {
                                                    return;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        loa_nr:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juhiluba>loa_nr");
            }
            clazz.LoaNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("loa_nr")).Value;
            goto START;
        loa_tyyp:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juhiluba>loa_tyyp");
            }
            clazz.LoaTyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("loa_tyyp")).Value;
            goto START;
        loa_staatus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juhiluba>loa_staatus");
            }
            clazz.LoaStaatus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("loa_staatus")).Value;
            goto START;
        loa_staatuse_kp:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juhiluba>loa_staatuse_kp");
            }
            clazz.LoaStaatuseKp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("loa_staatuse_kp")).Value;
            goto START;
        kategooriad:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juhiluba>kategooriad");
            }
            clazz.Kategooriad = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kategooriad")).Value;
            goto START;
        valja_kp:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juhiluba>valja_kp");
            }
            clazz.ValjaKp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("valja_kp")).Value;
            goto START;
        katte_kp:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juhiluba>katte_kp");
            }
            clazz.KatteKp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("katte_kp")).Value;
            goto START;
        kehtiv_kp:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juhiluba>kehtiv_kp");
            }
            clazz.KehtivKp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kehtiv_kp")).Value;
            goto START;
        lisaandmed:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juhiluba>lisaandmed");
            }
            global::Xtee.Core.SerializationMetadata metaLisaandmed = this.GetMetaData<Juhiluba.ILisaandmedType>(Reader, ">>juhiluba>lisaandmed", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
            clazz.Lisaandmed = metaLisaandmed.NewEntity<Juhiluba.ILisaandmedType>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("lisaandmed");
                metaLisaandmed.NewSerializer(clazz.Lisaandmed).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        juhiluba_kehtib:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juhiluba>juhiluba_kehtib");
            }
            clazz.JuhilubaKehtib = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("juhiluba_kehtib")).Value;
            goto START;
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>juhiluba>lisaandmed", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Juhiluba.LisaandmedType))]
        public class LisaandmedTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected Juhiluba.ILisaandmedType clazz;
            
            public LisaandmedTypeSerializer(Juhiluba.ILisaandmedType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                for (int x = 0; ((clazz.Eritingimus != null) 
                            && (x < clazz.Eritingimus.Count)); x = (x + 1)) {
                    if (clazz.Eritingimus[x]!=null) {
                        Writer.WriteStartElement("eritingimus");
                        global::Xtee.Core.SerializationMetadata metaEritingimus = this.GetMetaData(clazz.Eritingimus[x]);
                        Writer.WriteTypeAttribute(metaEritingimus.TypeQualifiedName.Namespace, metaEritingimus.TypeQualifiedName.Name);
                        metaEritingimus.NewSerializer(clazz.Eritingimus[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="eritingimus") {
                    clazz.Eritingimus = new System.Collections.Generic.List<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IEritingimus>();
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "eritingimus")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>juhiluba>lisaandmed>eritingimus");
                        }
                        global::Xtee.Core.SerializationMetadata metaEritingimus = this.GetMetaData<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IEritingimus>(Reader, "eritingimus", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                        global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IEritingimus item = metaEritingimus.NewEntity<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IEritingimus>();
                        clazz.Eritingimus.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("eritingimus");
                            metaEritingimus.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                }
            }
        }
    }
}
